﻿Public Class dungeonObject

    Private _id As Integer = -1
    Private _name As String
    Private _desc As String
    Private _type As String
    Private _model As String
    Private _texture As String

    Public Property ID() As Integer
        Get
            Return _id
        End Get
        Set(ByVal value As Integer)
            _id = value
        End Set
    End Property

    Public Property Name() As String
        Get
            Return _name
        End Get
        Set(ByVal value As String)
            _name = value
        End Set
    End Property

    Public Property Description() As String
        Get
            Return _desc
        End Get
        Set(ByVal value As String)
            _desc = value
        End Set
    End Property

    Public Property ObjectType() As String
        Get
            Return _type
        End Get
        Set(ByVal value As String)
            _type = value
        End Set
    End Property

    Public Property ModelName() As String
        Get
            Return _model
        End Get
        Set(ByVal value As String)
            _model = value
        End Set
    End Property

    Public Property TextureName() As String
        Get
            Return _texture
        End Get
        Set(ByVal value As String)
            _texture = value
        End Set
    End Property

    Public ReadOnly Property IsValid() As Boolean
        Get
            If _name = "" Then Return False
            If _type = "" Then Return False
            Return True
        End Get
    End Property

    Public Function ToXElement() As XElement
        Dim result As XElement = <dungeonObj id=<%= _id %>>
                                     <name><%= _name %></name>
                                     <desc><%= _desc %></desc>
                                     <type><%= _type %></type>
                                     <model><%= _model %></model>
                                     <texture><%= _texture %></texture>
                                 </dungeonObj>
        Return result
    End Function

    Public Sub LoadXML(ByVal dungeonObjXML As String)
        Dim doX As XElement = GetXElement(dungeonObjXML)

        If IsNothing(doX) Then
            Exit Sub
        End If

        If Integer.TryParse(doX.@id, _id) = False Then
            _id = Nothing
        End If
        _name = doX.<name>.Value
        _desc = doX.<desc>.Value
        _type = doX.<type>.Value
        _model = doX.<model>.Value
        _texture = doX.<texture>.Value
    End Sub

End Class
